<?php
class house_esf extends base{

	public function init(){ // 公用
		parent::init(); // 这是必须的

		$this->tit = "二手房";
		$this->current = 'house_esf';

		$this->orderType = arg('c');

		$this->houseObj = D($this->orderType);
		$this->house_logObj = D($this->orderType.'_log');

		$this->confObj = D('house_conf');
		$this->zoneObj = D('house_zone');
		$this->companyObj = D('company');
		$this->storeObj = D('company_store');
		$this->adminObj = D('company_user');
		
		$this->areaObj = D('city');
		$this->cateObj = D('cate');

		$this->areas = $this->areaObj->get_citys_byid($this->company['area_id']);
		
		// dump($this->cates);exit;
		$this->cate = $this->cateObj->find(array("status=1 and url='{$this->orderType}'"));
		$this->cates = $this->cateObj->get_cates($this->cate['id']);


		$this->tings = $this->confObj->get_conf('厅室');
		$this->chaox = $this->confObj->get_conf('朝向');
		$this->fangl = $this->confObj->get_conf('房龄');
		$this->louc = $this->confObj->get_conf('楼层');
		$this->leix = $this->confObj->get_conf('类型');
		$this->chanq = $this->confObj->get_conf('产权');
		$this->zhuangx = $this->confObj->get_conf('装修');
		// dump($this->zhuangx);exit;
		$this->mianjis = $this->confObj->get_conf('面积');
		$this->jiages = $this->confObj->get_conf('售价');

	}

	//共享房源
	public function index(){
		$this->current = 'house';

		$this->tab = $this->tab?$this->tab:'1';
		$arrBase = array('tab' => $this->tab,'page' => '0000',);
		if($this->keyword){
			$arrBase = array_merge($arrBase,array('keyword' => $this->keyword));
		}
		$this->nextpage = url($this->controller,'loaddata', $arrBase);

	}


	//loaddata
	public function loaddata(){
		
		$cond = "status=1 ".$this->cond_city;
		if($this->tab){
			// $cond .=" and order_status={$this->tab}";
		}
		//权限
		switch($this->tab){
			case '1':
				$cond .=" and is_show=1 and is_share=1";
				break;
			case '2':
				$cond .=" and is_show=1 and company_id={$this->company['id']}";
				break;
			case '3':
				$cond .=" and is_show=1 and store_id={$this->store['id']}";
				break;
		}


		//搜索
		if($this->keyword){
			$cond.=" and (title like '%".$this->keyword."%' or intro like '%".$this->keyword."%') ";
		}

		$page = (int)arg("page", 1);
		$result = $this->houseObj->findAll(array($cond),'id desc','*',array($page, 5));
		$this->pager = $this->houseObj->page;
		
        if($this->pager){  //2页的意思
			if($this->pager['total_page'] < arg('page') ) {
	            die('0');
	        }
		}else{
			if(arg('page')>1) {
	            die('0');
	        }
		}

		if($result){
			foreach ($result as $val) {
				if($val['photo']){
					$photoss = explode(',', $val['photo']);
					foreach($photoss as $v){
                        $v2 = D('upload_file')->get_image($v);
                        $v2 = $v2['file_path'];

                        $val['photos'][] = $v2;
                        $val['thumbs'][] = $v2;
                    }
					$val['img'] = $val['photos'][0];
				}
				$list[] = $val;
			}
			$this->areas = $this->areaObj->ids($result,'area_id');
			$this->cates = $this->cateObj->ids($result,'cate_id');
			$this->zones = $this->zoneObj->ids($result,'zone_id');
			$this->companys = $this->companyObj->ids($result,'company_id');
			$this->stores = $this->storeObj->ids($result,'store_id');
			$this->members = $this->adminObj->ids($result,'admin_id');
			// $this->shifus = $this->memberObj->ids($result,'shifu_id');
			
			$this->list = $list;

		}else{
			die('0');
		}
		

	}


	//我的房源
	public function manage(){
		$this->current = 'my';

		$this->tab = $this->tab?$this->tab:'1';
		$arrBase = array('tab' => $this->tab,'page' => '0000',);
		if($this->keyword){
			$arrBase = array_merge($arrBase,array('keyword' => $this->keyword));
		}
		$this->nextpage = url($this->controller,'manage_loaddata', $arrBase);

	}


	//loaddata
	public function manage_loaddata(){
		
		$cond = "status=1 ".$this->cond_base;
		//权限
		switch($this->tab){
			case '1':
				$cond .=" and is_share=1 and is_show=1";
				break;
			case '2':
				$cond .=" and is_show=1";
				break;
			case '3':
				$cond .=" and is_show=0";
				break;
		}

		//权限
		switch($this->admin['level']){
			case '4'://总监
				$cond .=" and company_id={$this->company['id']}";
				break;
			case '3'://区经
				$cond .=" and company_id={$this->company['id']}";
				break;
			case '2'://店长
				$cond .=" and store_id={$this->store['id']}";
				break;
			case '1':
				if($this->admin['user_id']){
					$cond .=" and (admin_id={$this->admin_id} or user_id={$this->admin['user_id']})";
				}else{
					$cond .=" and admin_id={$this->admin_id}";
				}
				break;
		}

		//搜索
		if($this->keyword){
			$cond.=" and (title like '%".$this->keyword."%' or intro like '%".$this->keyword."%' and local like '%".$this->keyword."%') ";
		}

		$page = (int)arg("page", 1);
		$result = $this->houseObj->findAll(array($cond),'id desc','*',array($page, 5));
		$this->pager = $this->houseObj->page;
		
        if($this->pager){  //2页的意思
			if($this->pager['total_page'] < arg('page') ) {
	            die('0');
	        }
		}else{
			if(arg('page')>1) {
	            die('0');
	        }
		}

		if($result){
			foreach ($result as $val) {
				if($val['photo']){
					$photoss = explode(',', $val['photo']);
					foreach($photoss as $v){
                        $v2 = D('upload_file')->get_image($v);
                        $v2 = $v2['file_path'];

                        $val['photos'][] = $v2;
                        $val['thumbs'][] = $v2;
                    }
					$val['img'] = $val['photos'][0];
				}
				$list[] = $val;
			}
			$this->areas = $this->areaObj->ids($result,'area_id');
			$this->cates = $this->cateObj->ids($result,'cate_id');
			$this->zones = $this->zoneObj->ids($result,'zone_id');
			$this->members = $this->adminObj->ids($result,'admin_id');
			// $this->shifus = $this->memberObj->ids($result,'shifu_id');
			
			$this->list = $list;

		}else{
			die('0');
		}
		

	}


	//详情
	public function detail(){
		$id = arg('id');
		$info = $this->houseObj->findById($id);
		if($info){
			if($info['photo']){
				$this->photos = D('upload_file')->get_image_arr($info['photo']);
			}
			$this->info = $info;
		
			$this->member = $this->adminObj->findById($info['admin_id']);
			// $this->shifu = $this->memberObj->findById($info['shifu_id']);
			
			$logs = $this->house_logObj->findAll(array("status=1 and house_id={$info['id']}"));
			if($logs){
				foreach ($logs as $key => $val) {
					if($val['msg']){
						$val['msg'] = unserialize($val['msg']);
						if($val['msg']['photo']){
							$val['msg']['photos'] = explode(',', $val['msg']['photo']);
						}
						
					}
					$list[] = $val;
				}

				$this->logs = $list;
				$this->maxid = max(array_keys($this->logs));
			}

		}
	}


	//添加
	public function add(){
		if($this->fmdo == 'add'){
			
			$order_status = 1;

			$title = arg('title');
			$house_mianji = arg('house_mianji');
			$house_jiage = arg('house_jiage');

			$zone = $this->zoneObj->find(array("name='{$title}'"));
			if($zone){
				$zone_id = $zone['id'];
			}else{
				$zone_id = 0;
			}

			$house_danjia = intval($house_jiage * 10000 / $house_mianji);
			
			$arrBase = array(
				'city_id'=>$this->site['area_id'],
				'area_id'=>$this->company['area_id'],
				'cate_pid'=>$this->cate['id'],
				'cate_id'=>arg('cate_id'),
				'zone_id'=>$zone_id,
				'company_id'=>$this->company['id'],
				'store_id'=>$this->store['id'],
				'admin_id'=>$this->admin['id'],
				'title'=>$title,
				'house_mianji'=>$house_mianji,
				'house_jiage'=>$house_jiage,
				'house_danjia'=>$house_danjia,
				'house_tings'=>arg('house_tings'),
				'house_chaox'=>arg('house_chaox'),
				'house_fangl'=>arg('house_fangl'),
				'house_louc'=>arg('house_louc'),
				'house_leix'=>arg('house_leix'),
				'house_chanq'=>arg('house_chanq'),
				'house_zhuangx'=>arg('house_zhuangx'),
				'is_share'=>arg('is_share'),
				'is_show'=>arg('is_show'),
				'intro'=>arg('intro'),
				'order_status' =>$order_status,
				'photo'=>joinStr(arg('photo')),
				'add_time' =>date('Y-m-d H:i:s'),
				'up_time' =>date('Y-m-d H:i:s'),
				'status' =>1,
			);
			// dump($arrBase);exit;
			$house_id = $this->houseObj->add($arrBase);
			if($house_id){
				
				//log
				$data = array(
					'msg'=>'发布了新房源',
				);
				// $this->order_logObj->add_log($house_id,$data,$order_status);
			}
			
			$this->renderSuccess('提交成功','/'.$this->routeUrl.'/manage?tab=2');
		}

		$this->info = array('status'=>1,'is_show'=>1,'is_share'=>1);
		$this->display($this->routeUrl."/set.php");
		
	}
	
	//编辑
	public function edit(){
		$house_id = arg('id');
		if($this->fmdo == 'edit'){
			
			$order_status = 1;

			$title = arg('title');
			$house_mianji = arg('house_mianji');
			$house_jiage = arg('house_jiage');

			$zone = $this->zoneObj->find(array("name='{$title}'"));
			if($zone){
				$zone_id = $zone['id'];
			}else{
				$zone_id = 0;
			}

			$house_danjia = intval($house_jiage * 10000 / $house_mianji);
			
			$arrBase = array(
				// 'city_id'=>$this->site['area_id'],
				// 'area_id'=>$this->company['area_id'],
				// 'cate_pid'=>$this->cate['id'],
				'cate_id'=>arg('cate_id'),
				'zone_id'=>$zone_id,
				// 'company_id'=>$this->company['id'],
				// 'store_id'=>$this->store['id'],
				// 'admin_id'=>$this->admin['id'],
				'title'=>$title,
				'house_mianji'=>$house_mianji,
				'house_jiage'=>$house_jiage,
				'house_danjia'=>$house_danjia,
				'house_tings'=>arg('house_tings'),
				'house_chaox'=>arg('house_chaox'),
				'house_fangl'=>arg('house_fangl'),
				'house_louc'=>arg('house_louc'),
				'house_leix'=>arg('house_leix'),
				'house_chanq'=>arg('house_chanq'),
				'house_zhuangx'=>arg('house_zhuangx'),
				'is_share'=>arg('is_share'),
				'is_show'=>arg('is_show'),
				'intro'=>arg('intro'),
				'order_status' =>$order_status,
				'photo'=>joinStr(arg('photo')),
				// 'add_time' =>date('Y-m-d H:i:s'),
				'up_time' =>date('Y-m-d H:i:s'),
			);
			// dump($arrBase);exit;
			$this->houseObj->update(array('id'=>$house_id), $arrBase);
			if($house_id){
				//log
				$data = array(
					'msg'=>'重新编辑了信息',
				);
				// $this->order_logObj->add_log($house_id,$data,$order_status);
			}
			
			
			$this->renderSuccess('编辑成功','/'.$this->controller.'/index?tab='.$order_status);
		}

		$info = $this->modelObj->findById($house_id);
		$info['cate'] = $this->cateObj->findById($this->info['cate_id']);
		if($info['photo']){
			$this->photos = D('upload_file')->get_image_arr($info['photo']);
		}
		$this->info = $info;
		$this->display($this->routeUrl."/set.php");
		
	}

	//上架
	public function show(){
		$doids = arg('doids');
		$info = $this->houseObj->findById($doids);

		switch($info['is_show']){
			case '0':
				$msg ="上架";
				$show_status = 1;
				$share_status = $info['is_share'];
				break;
			case '1':
				$msg ="下架";
				$show_status = 0;
				$share_status = 0;
				break;
		}
			
		$arrBase = array(
			'is_show' =>$show_status,
			'is_share' =>$share_status,
			'up_time' =>date('Y-m-d H:i:s'),
			'status' =>1,
		);
		$this->houseObj->update(array('id'=>$doids), $arrBase);
		$this->renderSuccess($msg.'成功','/'.$this->controller.'/manage?tab='.$this->tab);
	}

	//共享
	public function share(){
		$doids = arg('doids');
		$info = $this->houseObj->findById($doids);

		switch($info['is_share']){
			case '0':
				$msg ="共享";
				$show_status = 1;
				$share_status = 1;
				break;
			case '1':
				$msg ="取消共享";
				$show_status = $info['is_show'];
				$share_status = 0;
				break;
		}
			
		$arrBase = array(
			'is_show' =>$show_status,
			'is_share' =>$share_status,
			'up_time' =>date('Y-m-d H:i:s'),
			'status' =>1,
		);
		$this->houseObj->update(array('id'=>$doids), $arrBase);
		$this->renderSuccess($msg.'成功','/'.$this->controller.'/manage?tab='.$this->tab);
	}

	//刷新
	public function shuaxin(){
		$doids = arg('doids');
		$info = $this->houseObj->findById($doids);

		// switch($info['is_show']){
		// 	case '0':
		// 		$msg ="上架";
		// 		$show_status = 1;
		// 		$share_status = $info['is_share'];
		// 		break;
		// 	case '1':
		// 		$msg ="下架";
		// 		$show_status = 0;
		// 		$share_status = 0;
		// 		break;
		// }
			
		$arrBase = array(
			'up_time' =>date('Y-m-d H:i:s'),
			'status' =>1,
		);
		$this->houseObj->update(array('id'=>$doids), $arrBase);
		$this->renderSuccess('刷新成功','/'.$this->controller.'/manage?tab='.$this->tab);
	}

	

	














	//oa列表
	public function oa(){
		$this->current = 'my';

		$this->tab = $this->tab?$this->tab:'1';
		$arrBase = array('tab' => $this->tab,'page' => '0000',);
		if($this->keyword){
			$arrBase = array_merge($arrBase,array('keyword' => $this->keyword));
		}
		$this->nextpage = url($this->controller,'oa_loaddata', $arrBase);

	}


	//loaddata
	public function oa_loaddata(){
		
		$cond = "status=1 ".$this->cond_company;
		if($this->tab){
			$cond .=" and order_status={$this->tab}";
		}

		//权限
		switch($this->user['level']){
			case '10':
				$cond .=" ";
				break;
			case '3'://区域经理
				$cond .=" and company_id={$this->company['id']}";
				break;
			case '2':
				$cond .=" and store_id={$this->store['id']}";
				break;
			case '1':
				$cond .=" and member_id={$this->user_id}";
				break;
		}

		//搜索
		if($this->keyword){
			$cond.=" and (title like '%".$this->keyword."%' or intro like '%".$this->keyword."%' and local like '%".$this->keyword."%') ";
		}

		$page = (int)arg("page", 1);
		$result = $this->modelObj->findAll(array($cond),'id desc','*',array($page, 5));
		$this->pager = $this->modelObj->page;
		
        if($this->pager){  //2页的意思
			if($this->pager['total_page'] < arg('page') ) {
	            die('0');
	        }
		}else{
			if(arg('page')>1) {
	            die('0');
	        }
		}

		if($result){
			foreach ($result as $val) {
				if($val['photo']){
					$photos = explode(',', $val['photo']);
					$val['img'] = $photos[0];
				}
				$list[] = $val;
			}
			$this->cates = $this->cateObj->ids($result,'cate_id');
			$this->zones = $this->zoneObj->ids($result,'zone_id');
			$this->members = $this->memberObj->ids($result,'member_id');
			$this->shifus = $this->memberObj->ids($result,'shifu_id');
			
			$this->list = $list;

		}else{
			die('0');
		}
		

	}

	

	//匹配
	public function pipei_search(){
		$id = arg('id');
		if($this->fmdo == 'pipei_search'){
			$arrBase = array(
				'id' => arg('id'),
				'title' => arg('title'),
				'house_mianji' => arg('house_mianji'),
				'house_jiage' => arg('house_jiage'),
				'house_tings' => arg('house_tings'),
				'house_chaox' => arg('house_chaox'),
				'house_fangl' => arg('house_fangl'),
				'house_louc' => arg('house_louc'),
				'house_leix' => arg('house_leix'),
				'house_chanq' => arg('house_chanq'),
			);
			$this->nextpage = url($this->controller,'pipei', $arrBase);
			
			$this->ajaxMsg('数据匹配中',1,$this->nextpage);
		}
		$this->info = $this->modelObj->findById($id);

	}

	
	public function pipei(){

		$this->tab = $this->tab?$this->tab:'1';
		$arrBase = array('tab' => $this->tab,'page' => '0000',);

		$arrAdd = array(
			'id' => arg('id'),
			'title' => arg('title'),
			'house_mianji' => arg('house_mianji'),
			'house_jiage' => arg('house_jiage'),
			'house_tings' => arg('house_tings'),
			'house_chaox' => arg('house_chaox'),
			'house_fangl' => arg('house_fangl'),
			'house_louc' => arg('house_louc'),
			'house_leix' => arg('house_leix'),
			'house_chanq' => arg('house_chanq'),
			'house_chanq' => arg('house_chanq'),
		);
		if($this->keyword){
			$arrAdd = array_merge($arrAdd,array('keyword' => $this->keyword));
		}

		$arrBase = array_merge($arrBase,$arrAdd);
		$this->nextpage = url($this->controller,'pipei_loaddata', $arrBase);


		$pageurl = "";
		foreach ($arrAdd as $key => $val) {
			if($val) $pageurl .= "&{$key}={$val}";
		}
		$this->pageurl = $pageurl;
		// dump($this->pageurl);exit;
	}

	//loaddata
	public function pipei_loaddata(){
		

		$id = arg('id');
		$this->info = $this->modelObj->findById($id);

		$this->title = arg('title');
		$this->house_mianji = arg('house_mianji');
		$this->house_jiage = arg('house_jiage');
		$this->house_tings = arg('house_tings');
		$this->house_chaox = arg('house_chaox');
		$this->house_fangl = arg('house_fangl');
		$this->house_louc = arg('house_louc');
		$this->house_leix = arg('house_leix');
		$this->house_chanq = arg('house_chanq');

		$cond = "status=1";
		//权限
		switch($this->tab){
			case '1':
				$cond .=" and is_show=1 and is_share=1";
				break;
			case '2':
				$cond .=" and is_show=1 and company_id={$this->company['id']}";
				break;
			case '3':
				$cond .=" and is_show=1 and store_id={$this->store['id']}";
				break;
		}

		if($this->title){
			$cond.=" and (title like '%".$this->info['title']."%') ";
		}
		if($this->house_mianji){
			$res = $this->confObj->get_num2('面积',$this->info['house_mianji']);
			if($res){
				$cond.=" and (house_mianji = {$res['val']}) ";
			}
		}
		if($this->house_jiage){
			$res = $this->confObj->get_num2('售价',$this->info['house_jiage']);
			if($res){
				$cond.=" and (house_jiage = {$res['val']}) ";
			}
		}
		if($this->house_tings){
			$cond.=" and (house_tings = '".$this->info['house_tings']."') ";
		}
		if($this->house_chaox){
			$cond.=" and (house_chaox = '".$this->info['house_chaox']."') ";
		}
		if($this->house_tings){
			$cond.=" and (house_tings = '".$this->info['house_tings']."') ";
		}
		if($this->house_fangl){
			$cond.=" and (house_fangl = '".$this->info['house_fangl']."') ";
		}
		if($this->house_louc){
			$cond.=" and (house_louc = '".$this->info['house_louc']."') ";
		}
		if($this->house_leix){
			$cond.=" and (house_leix = '".$this->info['house_leix']."') ";
		}
		if($this->house_chanq){
			$cond.=" and (house_chanq = '".$this->info['house_chanq']."') ";
		}
		if($this->keyword){
			$cond.=" and (title like '%".$this->keyword."%' or intro like '%".$this->keyword."%') ";
		}
		
		// dump($cond);exit;
		//权限
		// switch($this->user['level']){
		// 	case '10':
		// 		$cond .=" and company_id={$this->company['id']}";
		// 		break;
		// 	case '3':
		// 		$cond .=" and company_id={$this->company['id']}";
		// 		break;
		// 	case '2':
		// 		$cond .=" and company_id={$this->company['id']}";
		// 		break;
		// 	case '1':
		// 		if($this->tab==1){
		// 			$cond .=" ".$this->cond_cate.$this->cond_zone;
		// 		}else{
		// 			$cond .=" and company_id={$this->company['id']}";
		// 		}
		// 		break;
		// }

		//搜索
		if($this->keyword){
			$cond.=" and (title like '%".$this->keyword."%' or intro like '%".$this->keyword."%') ";
		}
		// dump($cond);
		$this->modelObj = D('qiugou');
		$page = (int)arg("page", 1);
		$result = $this->modelObj->findAll(array($cond),'id desc','*',array($page, 5));
		$this->pager = $this->modelObj->page;
		
        if($this->pager){  //2页的意思
			if($this->pager['total_page'] < arg('page') ) {
	            die('0');
	        }
		}else{
			if(arg('page')>1) {
	            die('0');
	        }
		}

		if($result){
			foreach ($result as $val) {
				if($val['photo']){
					$photos = explode(',', $val['photo']);
					$val['img'] = $photos[0];
				}
				$list[] = $val;
			}
			$this->cates = $this->cateObj->ids($result,'cate_id');
			$this->zones = $this->zoneObj->ids($result,'zone_id');
			$this->companys = $this->companyObj->ids($result,'company_id');
			$this->stores = $this->storeObj->ids($result,'store_id');
			$this->members = $this->memberObj->ids($result,'member_id');
			$this->shifus = $this->memberObj->ids($result,'shifu_id');
			
			$this->list = $list;

		}else{
			die('0');
		}
		

	}


	public function search(){
		$this->type = arg('type');
		// $this->cate = $this->cateObj->find(array("url='{$url}' and status=1"));
	}




	

	//取消99
	public function quxiao(){
		$order_id = arg('id');
		if($this->fmdo == 'quxiao'){
			$cate_id = arg('cate_id');
			$order_status = 99;
			$arrBase = array(
				'shifu_id'=>$this->user_id,
				'order_status' =>$order_status,
				'up_time' =>date('Y-m-d H:i:s'),
				'status' =>1,
			);
			$this->modelObj->update(array('id'=>$order_id), $arrBase);
			
			$data = array(
				'msg'=>'师傅取消了保洁',
				'intro'=>arg('intro'),
			);
			$this->order_logObj->add_log($order_id,$data,$order_status);

			//发送短信给区长
			// $this->send_to_user($order_id,99,'user1');
			

			$this->ajaxMsg('取消成功',1);
		}

		$this->info = $this->modelObj->findById($order_id);
		$this->cate = $this->cateObj->findById($this->info['cate_id']);
		$this->zone = $this->zoneObj->findById($this->info['zone_id']);
		if($this->info['photo']){
			$this->photos = explode(',', $this->info['photo']);
		}
	}

	//实勘2
	public function queren(){
		$order_id = arg('id');
		if($this->fmdo == 'queren'){

			$order_status = 2;
			$arrBase = array(
				'order_status' =>$order_status,
				'photo'=>joinStr(arg('photo')),
				'up_time' =>date('Y-m-d H:i:s'),
				'status' =>1,
			);
			$this->modelObj->update(array('id'=>$order_id), $arrBase);
			
			$data = array(
				'msg'=>'实勘了信息',
				'intro'=>arg('intro'),
			);
			$this->order_logObj->add_log($order_id,$data,$order_status);

			//发送短信给报修人
			// $this->send_to_user_sms($order_id,$order_status,'user1',$this->orderType);

			$this->ajaxMsg('实勘成功',1,'/'.$this->controller.'/index?tab='.$order_status);
		}

		$this->info = $this->modelObj->findById($order_id);
		if($this->info['photo']){
			$this->photos = explode(',', $this->info['photo']);
		}
	}

	//带看3
	public function daikan(){
		$order_id = arg('id');
		if($this->fmdo == 'daikan'){

			$order_status = 3;
			$arrBase = array(
				'order_status' =>$order_status,
				'photo'=>joinStr(arg('photo')),
				'up_time' =>date('Y-m-d H:i:s'),
				'status' =>1,
			);
			$this->modelObj->update(array('id'=>$order_id), $arrBase);
			
			$data = array(
				'msg'=>'带看了信息',
				'intro'=>arg('intro'),
			);
			$this->order_logObj->add_log($order_id,$data,$order_status);

			//发送短信给报修人
			// $this->send_to_user_sms($order_id,$order_status,'user1',$this->orderType);

			$this->ajaxMsg('带看成功',1,'/'.$this->controller.'/index?tab='.$order_status);
		}

		$this->info = $this->modelObj->findById($order_id);
		if($this->info['photo']){
			$this->photos = explode(',', $this->info['photo']);
		}
	}

	//跟进4
	public function genjin(){
		$order_id = arg('id');
		if($this->fmdo == 'genjin'){

			$order_status = 4;
			$arrBase = array(
				'order_status' =>$order_status,
				'photo'=>joinStr(arg('photo')),
				'up_time' =>date('Y-m-d H:i:s'),
				'status' =>1,
			);
			$this->modelObj->update(array('id'=>$order_id), $arrBase);
			
			$data = array(
				'msg'=>'跟进了信息',
				'intro'=>arg('intro'),
			);
			$this->order_logObj->add_log($order_id,$data,$order_status);

			//发送短信给报修人
			// $this->send_to_user_sms($order_id,$order_status,'user1',$this->orderType);

			$this->ajaxMsg('带看成功',1,'/'.$this->controller.'/index?tab='.$order_status);
		}

		$this->info = $this->modelObj->findById($order_id);
		if($this->info['photo']){
			$this->photos = explode(',', $this->info['photo']);
		}
	}

	//成交5
	public function chengjiao(){
		$order_id = arg('id');
		if($this->fmdo == 'chengjiao'){

			$order_status = 5;
			$arrBase = array(
				'order_status' =>$order_status,
				'photo'=>joinStr(arg('photo')),
				'up_time' =>date('Y-m-d H:i:s'),
				'status' =>1,
			);
			$this->modelObj->update(array('id'=>$order_id), $arrBase);
			
			$data = array(
				'msg'=>'成交了信息',
				'intro'=>arg('intro'),
			);
			$this->order_logObj->add_log($order_id,$data,$order_status);

			//发送短信给报修人
			// $this->send_to_user_sms($order_id,$order_status,'user1',$this->orderType);

			$this->ajaxMsg('带看成功',1,'/'.$this->controller.'/index?tab='.$order_status);
		}

		$this->info = $this->modelObj->findById($order_id);
		if($this->info['photo']){
			$this->photos = explode(',', $this->info['photo']);
		}
	}

	//手续6
	public function jindu(){
		$order_id = arg('id');
		if($this->fmdo == 'jindu'){

			$order_status = 6;
			$arrBase = array(
				'order_status' =>$order_status,
				'photo'=>joinStr(arg('photo')),
				'up_time' =>date('Y-m-d H:i:s'),
				'status' =>1,
			);
			$this->modelObj->update(array('id'=>$order_id), $arrBase);
			
			$data = array(
				'msg'=>'信息手续中',
				'intro'=>arg('intro'),
			);
			$this->order_logObj->add_log($order_id,$data,$order_status);

			//发送短信给报修人
			// $this->send_to_user_sms($order_id,$order_status,'user1',$this->orderType);

			$this->ajaxMsg('带看成功',1,'/'.$this->controller.'/index?tab='.$order_status);
		}

		$this->info = $this->modelObj->findById($order_id);
		if($this->info['photo']){
			$this->photos = explode(',', $this->info['photo']);
		}
	}

	//完成7
	public function wancheng(){
		$order_id = arg('id');
		if($this->fmdo == 'wancheng'){

			$order_status = 7;
			$arrBase = array(
				'order_status' =>$order_status,
				'photo'=>joinStr(arg('photo')),
				'up_time' =>date('Y-m-d H:i:s'),
				'status' =>1,
			);
			$this->modelObj->update(array('id'=>$order_id), $arrBase);
			
			$data = array(
				'msg'=>'信息已完成',
				'intro'=>arg('intro'),
			);
			$this->order_logObj->add_log($order_id,$data,$order_status);

			//发送短信给报修人
			// $this->send_to_user_sms($order_id,$order_status,'user1',$this->orderType);

			$this->ajaxMsg('信息已完成',1,'/'.$this->controller.'/index?tab='.$order_status);
		}

		$this->info = $this->modelObj->findById($order_id);
		if($this->info['photo']){
			$this->photos = explode(',', $this->info['photo']);
		}
	}



	//重派2
	public function chongpai(){
		$order_id = arg('id');
		if($this->fmdo == 'chongpai'){
			$cate_id = arg('cate_id');
			$order_status = 2;
			$arrBase = array(
				'shifu_id'=>arg('shifu_id'),
				'shifu_id_cp'=>$this->user_id,
				'order_status' =>$order_status,
				'up_time' =>date('Y-m-d H:i:s'),
				'status' =>1,
			);
			$this->modelObj->update(array('id'=>$order_id), $arrBase);
			
			$data = array(
				'msg'=>''.$this->user_id.'信息重派了',
				'intro'=>arg('intro'),
			);
			$this->order_logObj->add_log($order_id,$data,$order_status);

			//发送短信给师傅
			$this->send_to_user_sms($order_id,$order_status,'user3',$this->orderType);
			

			$this->ajaxMsg('提交成功',1);
		}

		$this->info = $this->modelObj->findById($order_id);
		$this->shifu = $this->memberObj->findById($this->info['shifu_id']);
		$this->cate = $this->cateObj->findById($this->info['cate_id']);
		$this->zone = $this->zoneObj->findById($this->info['zone_id']);
		if($this->info['photo']){
			$this->photos = explode(',', $this->info['photo']);
		}
	}


	//成交5
	public function chengjiao1(){
		$order_id = arg('id');
		if($this->fmdo == 'chengjiao'){
			$cate_id = arg('cate_id');

			//佣金计算
			$info = $this->modelObj->findById($order_id);
			$cate_id = $info['cate_id'];
			$cate = $this->cateObj->findById($cate_id);
			$yj1 = $cate['yj1'];
			$yj2 = $cate['yj2'];
			//自定义佣金
			$cond = "company_id={$info['company_id']} and cate_id={$cate_id} and status=1";
			$cate_yj = $this->cate_yjObj->find(array($cond));
			if($cate_yj){
				$yj1 = $cate_yj['yj1'];
				$yj2 = $cate_yj['yj2'];
			}

			$house_jiage = arg('house_jiage');
			//单价
			$house_danjia = intval($house_jiage * 10000 / $info['house_mianji']);

			$yj_money1 = $house_jiage * 10000 * $yj1 / 100 ;
			$yj_money2 = $yj_money1 * $yj2 / 100 ;
			//计算完成
			$order_status = 5;
			$arrBase = array(
				'house_jiage'=>arg('house_jiage'),
				'house_danjia'=>$house_danjia,
				'kh_name'=>arg('kh_name'),
				'kh_tel'=>arg('kh_tel'),
				'yj_money1' =>$yj_money1,
				'yj_money2' =>$yj_money2,
				'order_status' =>$order_status,
				'up_time' =>date('Y-m-d H:i:s'),
				'status' =>1,
			);
			$this->modelObj->update(array('id'=>$order_id), $arrBase);
			
			$data = array(
				'msg'=>'信息已成交',
				'intro'=>arg('intro'),
				'photo'=>joinStr(arg('photo')),
				'yj_money1' =>$yj_money1,
				'yj_money2' =>$yj_money2,
				'house_jiage'=>arg('house_jiage'),
			);
			$this->order_logObj->add_log($order_id,$data,$order_status);

			//moneylog
			// $this->manageObj->add_money(arg('manage_id'),arg('yj_money'));
			// $this->money_logObj->add_log(arg('manage_id'),'房源成交佣金结算',arg('yj_money'));
			
			//发送短信给报修人
			$this->send_to_user_sms($order_id,$order_status,'user1',$this->orderType);

			$this->ajaxMsg('提交成功',1);
		}

		$this->info = $this->modelObj->findById($order_id);
		$this->cate = $this->cateObj->findById($this->info['cate_id']);
		$this->zone = $this->zoneObj->findById($this->info['zone_id']);
		if($this->info['photo']){
			$this->photos = explode(',', $this->info['photo']);
		}
	}

	//手续中6
	public function jindu1(){
		$order_id = arg('id');
		if($this->fmdo == 'jindu'){
			$cate_id = arg('cate_id');
			$order_status = 5;
			$arrBase = array(
				'shifu_id'=>$this->user_id,
				'order_status' =>$order_status,
				'up_time' =>date('Y-m-d H:i:s'),
				'status' =>1,
			);
			$this->modelObj->update(array('id'=>$order_id), $arrBase);
			
			$data = array(
				'msg'=>'信息办理手续中',
				'intro'=>arg('intro'),
				'photo'=>joinStr(arg('photo')),
			);
			$this->order_logObj->add_log($order_id,$data,$order_status);

			//发送短信给报修人
			$this->send_to_user_sms($order_id,$order_status,'user1',$this->orderType);

			$this->ajaxMsg('提交成功',1);
		}

		$this->info = $this->modelObj->findById($order_id);
		$this->cate = $this->cateObj->findById($this->info['cate_id']);
		$this->zone = $this->zoneObj->findById($this->info['zone_id']);
		if($this->info['photo']){
			$this->photos = explode(',', $this->info['photo']);
		}
	}

	//完成6
	public function wancheng1(){
		$order_id = arg('id');
		if($this->fmdo == 'wancheng'){
			$cate_id = arg('cate_id');
			$order_status = 6;
			$arrBase = array(
				// 'shebei'=>arg('shebei'),
				// 'cailiao'=>arg('cailiao'),
				// 'cl_money'=>arg('cl_money'),
				// 'rg_money'=>arg('rg_money'),
				// 'z_money' =>arg('cl_money') + arg('rg_money'),
				'order_status' =>$order_status,
				'up_time' =>date('Y-m-d H:i:s'),
				'status' =>1,
			);
			$this->modelObj->update(array('id'=>$order_id), $arrBase);
			
			$data = array(
				'msg'=>'信息已完成了',
				'intro'=>arg('intro'),
				'photo'=>joinStr(arg('photo')),
			);
			$this->order_logObj->add_log($order_id,$data,$order_status);

			//moneylog
			// $this->manageObj->add_money(arg('manage_id'),arg('yj_money'));
			// $this->money_logObj->add_log(arg('manage_id'),'房源成交佣金结算',arg('yj_money'));
			
			//发送短信给报修人
			$this->send_to_user_sms($order_id,$order_status,'user1',$this->orderType);

			$this->ajaxMsg('提交成功',1);
		}

		$this->info = $this->modelObj->findById($order_id);
		$this->cate = $this->cateObj->findById($this->info['cate_id']);
		$this->zone = $this->zoneObj->findById($this->info['zone_id']);
		if($this->info['photo']){
			$this->photos = explode(',', $this->info['photo']);
		}
	}

	//评价8
	public function pingjia(){
		$order_id = arg('id');
		if($this->fmdo == 'pingjia'){
			$cate_id = arg('cate_id');
			$order_status = 8;
			$arrBase = array(
				'star_wx' =>arg('star_wx'),
				'star_sf' =>arg('star_sf'),
				'star_info' =>arg('star_info'),
				'order_status' =>$order_status,
				'up_time' =>date('Y-m-d H:i:s'),
				'status' =>1,
			);
			$this->modelObj->update(array('id'=>$order_id), $arrBase);
			
			$data = array(
				'msg'=>'评价了保洁',
				'intro'=>arg('intro'),
				'photo'=>joinStr(arg('photo')),
			);
			$this->order_logObj->add_log($order_id,$data,$order_status);

			//moneylog
			// $this->manageObj->incr(array('id'=>$info['manage_id']), 'money', $money);
			// $this->money_logObj->add_log($info['area_id'],$info['manage_id'],$money,'房源已完成佣金结算');
			 
			//发送短信给师傅
			$this->send_to_user_sms($order_id,$order_status,'user3',$this->orderType);

			$this->ajaxMsg('评价成功',1);
		}

		$this->info = $this->modelObj->findById($order_id);
		$this->cate = $this->cateObj->findById($this->info['cate_id']);
		$this->zone = $this->zoneObj->findById($this->info['zone_id']);
		if($this->info['photo']){
			$this->photos = explode(',', $this->info['photo']);
		}
	}

	//查看评价
	public function pingjia_look(){
		$id = arg('id');
		$info = $this->modelObj->findById($id);
		if($info['star_wx']){
			for ($i=1; $i <= $info['star_wx']; $i++) { 
				$star_wx[$i] = 'checked';
			}
			for ($i=1; $i <= $info['star_sf']; $i++) { 
				$star_sf[$i] = 'checked';
			}
			$this->star_wx = $star_wx;
			$this->star_sf = $star_sf;
		}
		$this->info = $info;
	}


	//ajax_zone
	public function ajax_zone(){
		$id = arg('id');
		if($id){
			$this->zone = $this->zoneObj->findById($id);

			$cond = "status=1 and parent_id={$id} and id IN ({$this->user['zone_ids']})".$this->cond_base;
			$this->list = $this->zoneObj->findAll(array($cond),'orderby asc');
		}
	}

	//ajax_shifu
	public function ajax_shifu(){
		$cate_id = arg('id');
		$zone_id = arg('zone_id');
		if($cate_id){
			$this->list = $this->memberObj->get_shifu($this->company['id'],$cate_id,$zone_id,$this->orderType);

			if($this->list && count($this->list)==1){
				header('Content-Type:application/json; charset=utf-8');
    			$data = array();
				$data['code'] = 1;
				$data['id'] = $this->list[0]['id'];
				$data['realname'] = $this->list[0]['realname'];
				$data['tel'] = $this->list[0]['tel'];
				exit(json_encode($data));
				// $this->ajaxMsg($this->list[0]['id'],1);
			}
		}
	}

	//order_notice
	public function order_notice(){
		$tixing = 0;
		$cond ="status=1 and order_status<3 ".$this->cond_base;

		switch($this->group['level']){
			case '10'://管理员
				if($this->company_config['order_tx10']) $tixing = 1;
				$cond .="";
				break;
			case '3'://经纪人
				if($this->company_config['order_tx3']) $tixing = 1;

				if($this->company_config['bx_moshi']==1){
					$cond .=" ".$this->cond_cate.$this->cond_zone;
				}else{
					$cond .=" and shifu_id={$this->user_id}";
				}
				break;
			case '4'://师傅
				if($this->company_config['order_tx4']) $tixing = 1;

				if($this->company_config['bx_moshi']==1){
					$cond .=" ".$this->cond_cate.$this->cond_zone;
				}else{
					$cond .=" and shifu_id={$this->user_id}";
				}
				break;
		}

		// $cond .=" and order_status<3";
		$order = $this->modelObj->findCount(array($cond));
		if($order && $tixing){
			exit('success');
		}
	}


	
}